package com.timguan.render.dao.manager.cms;

import com.timguan.render.dao.domain.cms.CmsResourceConfigDO;
import com.timguan.render.dao.domain.cms.CmsResourceConfigDOExample;
import com.timguan.render.dao.persistence.cms.CmsResourceConfigDOMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * Created by guankaiqiang on 16/7/30.
 */
public class CmsResourceConfigManagerImpl {
    @Autowired
    private CmsResourceConfigDOMapper cmsResourceConfigDOMapper;

    public List<CmsResourceConfigDO> getCmsResourceConfigDOsByResType(String resourceType) {
        CmsResourceConfigDOExample CmsResourceConfigDOExample = new CmsResourceConfigDOExample();
        CmsResourceConfigDOExample.createCriteria().andResTypeEqualTo(resourceType).andIsDeleteEqualTo(0);
        return cmsResourceConfigDOMapper.selectByExample(CmsResourceConfigDOExample);
    }

    public CmsResourceConfigDO getCmsResourceConfigDOByName(String name) {
        CmsResourceConfigDOExample CmsResourceConfigDOExample = new CmsResourceConfigDOExample();
        CmsResourceConfigDOExample.createCriteria().andNameEqualTo(name).andIsDeleteEqualTo(0);
        List<CmsResourceConfigDO> CmsResourceConfigDOs = cmsResourceConfigDOMapper.selectByExample(CmsResourceConfigDOExample);
        if (CmsResourceConfigDOs != null && CmsResourceConfigDOs.size() != 0) {
            return CmsResourceConfigDOs.get(0);
        }
        return null;
    }

    public List<CmsResourceConfigDO> getCmsResourceConfigDOByNames(String... names) {
        List<String> nameList = Arrays.asList(names);
        CmsResourceConfigDOExample CmsResourceConfigDOExample = new CmsResourceConfigDOExample();
        CmsResourceConfigDOExample.createCriteria().andNameIn(nameList).andIsDeleteEqualTo(0);
        return cmsResourceConfigDOMapper.selectByExample(CmsResourceConfigDOExample);
    }
}
